<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>待审批详情</title>
    <link href="../css/font.css" type="text/css" rel="stylesheet">
    <link href="../css/style.css" type="text/css" rel="stylesheet">
    <!--block[hdcss]-->

    <!--block[hdcss]end-->
</head>
<body>
<!--block[content]-->
<section class="wrap">
    <div class="page">
        <!--<header class="hd">头部 </header>-->
        <div class="m-check-status">
            <div class="u-btn u-btn-error" id="check_status_2"  style="display:none">未通过</div>
            <div class="u-btn u-btn-disabled" id="check_status_0" style="display:none">未审批</div>
            <div class="u-btn" style="display:none" id="check_status_1" >审核通过</div>
        </div>
        <ul class="m-info" id="m-info">

        </ul>
        <div class="m-tlt-s1">
            审批意见
        </div>
        <ul class="m-info">
            <li>
                <span class="list-val"><input type="text" id="des" placeholder="审批意见"></span>
            </li>
        </ul>
        <div class="u-btn-area">
            <div>
                <a class="u-btn u-btn-cancel" id="u-btn-cancel" href="javascript:;">
                    不通过
                </a>
            </div>
            <div>
                <a class="u-btn " id="submit" href="javascript:void(0)">
                    &nbsp;通&nbsp;&nbsp;过&nbsp;
                </a>
            </div>

        </div>
    </div>
</section>
<footer class="ft">底部</footer>
<script type="text/tmpl" id="jTmpl_list">
    <li>
        <div class="list-item">约见人</div>
        <span class="list-val"> {{inviter_name}}</span>

    </li>
    <li>
        <div class="list-item">标题</div>
        <span class="list-val"> {{subject}}</span>

    </li>
    <li>
        <div class="list-item">事由</div>
        <span class="list-val"> {{content}}</span>
    </li>
    <li>
        <div class="list-item">约见日期</div>
        <span class="list-val"> {{start_at}}</span>

    </li>
    <li>
        <div class="list-item">时长</div>
        <span class="list-val"> {{duration}}小时</span>

    </li>
    <li>
        <div class="list-item">联系方式</div>
        <span class="list-val">{{phone}}</span>
    </li>
</script>
<!--block[content]end-->
<script src="../js/lib/zepto.min.js" type="text/javascript"></script>
<script src="../js/lib/mustache.js" type="text/javascript"></script>
<script src="../js/plugin/juicer-min.js" type="text/javascript"></script>
<script type="text/javascript">

    window.alert = function (name) {
        var iframe = document.createElement("IFRAME");
        iframe.style.display = "none";
        iframe.setAttribute("src", 'data:text/plain,');
        document.documentElement.appendChild(iframe);
        window.frames[0].window.alert(name);
        iframe.parentNode.removeChild(iframe);
    };

    function getQueryString(name) {  
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
        var r = window.location.search.substr(1).match(reg);  
        if (r != null) return unescape(r[2]); return null;  
    };

    var getDate = function(url,callback){
        var type =  type || 'get';
        $.ajax({
            url:url,// 跳转到 action
            type:'get',
            dataType:'jsonp',
            success:function(data) {
                callback && callback(data);
            }
        });
    };

    let order_id = getQueryString('order_id') || '';

    const tpl = $('#jTmpl_list').html();

    const baseUrl = 'http://lres.gzhc365.com/gxyj/api/';
    let url = baseUrl + 'order/show?order_id='+order_id+'&callback=';
    getDate(url,function(data){
        console.log(data)
        if(data && data.code == 200){
            if(!data.data){
                alert('加载失败')
            }
            let element = Mustache.render(tpl, data.data);
            $('#m-info').html(element);
            $('#check_status_'+data.data.check_status).show();
        }else if(data.code == 1003){
            let l = window.location.href;
            window.location = 'http://lres.gzhc365.com/gxyj/api/auth/wx_authorize?return_url='+l
        }
    });

    //通过
    $('#submit').on('click',() => {
        let des = $('#des').val();
        if(des == ''){
            alert('审批意见不能为空');
            return false;
        }

        var data = {
            order_id:order_id,
            check_status:1,
            comment:des
        }

        $.ajax({
            url:'http://lres.gzhc365.com/gxyj/api/order/update_check_status',// 跳转到 action
            type:'post',
            data:data,
            xhrFields:{
                withCredentials: true
            },
            success:function(data) {
                if(data && data.code == 200){
                    alert('审批通过')
                    window.location = 'http://lres.gzhc365.com/gxyj/html/add.html';
                }
            }
        });
    });

    $('#u-btn-cancel').on('click',() => {
        let des = $('#des').val();
        if(des == ''){
            alert('审批意见不能为空');
            return false;
        }

        var data = {
            order_id:order_id,
            check_status:2,
            comment:des
        }

        $.ajax({
            url:'http://lres.gzhc365.com/gxyj/api/order/update_check_status',// 跳转到 action
            type:'post',
            data:data,
            xhrFields:{
                withCredentials: true
            },
            success:function(data) {
                if(data && data.code == 200){
                    alert('审批不通过')
                    window.location = 'http://lres.gzhc365.com/gxyj/html/add.html';
                }
            }
        });
    })

</script>
<!--block[endscript]end-->
</body>
</html>